package com.ruoyi.cs.service.impl;

import java.util.List;

import com.ruoyi.cs.mapper.TBoxMapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cs.mapper.TBoxTitleMapper;
import com.ruoyi.cs.domain.TBoxTitle;
import com.ruoyi.cs.service.ITBoxTitleService;

/**
 * 箱子标题Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Service
@SuppressWarnings("all")
public class TBoxTitleServiceImpl implements ITBoxTitleService 
{
    @Autowired
    private TBoxTitleMapper tBoxTitleMapper;

    @Autowired
    private TBoxMapper tBoxMapper;
    /**
     * 查询箱子标题
     * 
     * @param boxtitleId 箱子标题ID
     * @return 箱子标题
     */
    @Override
    public TBoxTitle selectTBoxTitleById(String boxtitleId)
    {
        return tBoxTitleMapper.selectTBoxTitleById(boxtitleId);
    }

    /**
     * 查询箱子标题列表
     * 
     * @param tBoxTitle 箱子标题
     * @return 箱子标题
     */
    @Override
    public List<TBoxTitle> selectTBoxTitleList(TBoxTitle tBoxTitle)
    {
        return tBoxTitleMapper.selectTBoxTitleList(tBoxTitle);
    }
    /**
     * 新增箱子标题
     * 
     * @param tBoxTitle 箱子标题
     * @return 结果
     */
    @Override
    public int insertTBoxTitle(TBoxTitle tBoxTitle)
    {
        tBoxTitle.setCreateTime(DateUtils.getNowDate());
        return tBoxTitleMapper.insertTBoxTitle(tBoxTitle);
    }

    /**
     * 修改箱子标题
     * 
     * @param tBoxTitle 箱子标题
     * @return 结果
     */
    @Override
    public int updateTBoxTitle(TBoxTitle tBoxTitle)
    {
        tBoxTitle.setUpdateTime(DateUtils.getNowDate());
        return tBoxTitleMapper.updateTBoxTitle(tBoxTitle);
    }

    /**
     * 批量删除箱子标题
     * 
     * @param boxtitleIds 需要删除的箱子标题ID
     * @return 结果
     */
    @Override
    public int deleteTBoxTitleByIds(String[] boxtitleIds)
    {
        /**判断箱子下面是否存在饰品，如果存在则不能删除*/
        int count = tBoxMapper.bacthTBoxCountDelect(boxtitleIds);
        if (count > 0) {
            return  Constants.FAILCODE;
        }
        return tBoxTitleMapper.updateTBoxTitleByIds(Constants.DELETE,boxtitleIds);
    }

    /**
     * 删除箱子标题信息
     * 
     * @param boxtitleId 箱子标题ID
     * @return 结果
     */
    @Override
    public int deleteTBoxTitleById(String boxtitleId)
    {
        return tBoxTitleMapper.deleteTBoxTitleById(boxtitleId);
    }

    /**
     * 批量启用箱子标题信息
     * @param delFlag
     * @param boxtitleIds
     * @return
     */
    @Override
    public int batchEnableTBoxTitle(String[] boxtitleIds) {
        return tBoxTitleMapper.updateTBoxTitleByIds(Constants.SUCCESS,boxtitleIds);
    }

    /**
     * 批量停用箱子标题信息
     * @param delFlag
     * @param boxtitleIds
     * @return
     */
    @Override
    public int batchStopTBoxTitle(String[] boxtitleIds) {
        /**判断箱子下面是否存在启用饰品，如果存在则不能停用*/
        int count = tBoxMapper.bacthTBoxCount(Constants.SUCCESS,boxtitleIds);
        if (count > 0) {
            return  Constants.FAILCODE;
        }
        return tBoxTitleMapper.updateTBoxTitleByIds(Constants.FAIL,boxtitleIds);
    }
}
